package com.nl.controller.web.mapper.impl;

import java.util.Date;
import java.util.List;

import org.apache.ibatis.session.ExecutorType;

import org.apache.ibatis.session.SqlSession;
import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.nl.controller.common.model.OperatorLog;
import com.nl.controller.web.mapper.TestMapper;
	
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Repository
public class TestMapperImpl implements TestMapper {
	
	@Autowired
    private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public List<OperatorLog> queryOperatorLogList() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int addBossSmSendTemp() {
		
		log.info("开始往待发表中插入数据");
        SqlSession session = null;
        
        int result = 0;
        try {
            Date date1 = new Date();
            session = sqlSessionTemplate.getSqlSessionFactory().openSession(ExecutorType.BATCH,false);
            
            //每次提交10000条
            int a = 10000;
            int stop=0;
            for (int i = 0; i < a; i++) {
                session.insert("addBossSmSendTemp");
/*                stop++;
                session.insert("addBossSmSendTemp2");
                stop++;
                session.insert("addBossSmSendTemp3");*/
                session.clearCache();
                //log.info("已经插入" + (stop + 1) + " 条");
                stop++;
            }
            session.commit();
            result=stop;
            Date date2=new Date();
            long time=date2.getTime()-date1.getTime();
            log.info("共耗时"+time+"毫秒");
            log.info("已经插入" + result  + " 条");
        } catch (Exception e) {
            e.printStackTrace();
            session.rollback();
            result=0;
        } finally {
            if (session != null) {
                session.close();
            }
        }
        return result;
	}

}
